<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/WorkspaceTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">
        <style>
            .ui-datatable table {
                text-align: center;
                border-collapse: collapse;
                width: 100%;
                border-color: grey;
                background-color: white;
            }
            .ui-datatable .ui-datatable-header, .ui-datatable .ui-datatable-footer {
                text-align: center;
                padding: 4px 10px 4px 160px;
            }
            .ui-inputfield, .ui-widget-content .ui-inputfield, .ui-widget-header .ui-inputfield {
                width: 60px;
            }
        </style>

        <h:form id="updateForm">
            <div style="border:1px solid gray;width:700px;overflow-y:hidden;overflow-x:scroll;">
                <div class="ui-datatable ui-widget">
                    <table border="1" summary="for all products">
                        <caption>
                            <div class="ui-datatable-header ui-widget-header ui-corner-tl ui-corner-tr">
                                Material Requirements Planning
                            </div>
                        </caption>

                        <tbody class="ui-datatable-data">
                            <tr>
                                <th class="ui-state-default"><h:outputText value="#{mrpMrpViewManagerBean.selectedMRP.bom.material.name}"/></th>
                                <th class="ui-state-default" colspan="2"><h:outputText value="Lead time = #{mrpMrpViewManagerBean.selectedMRP.bom.material.leadtime} weeks"/></th>
                                <th class="ui-state-default" colspan="2"><h:outputText value="Lot size = #{mrpMrpViewManagerBean.selectedMRP.bom.material.lotSize} kg"/></th>
                                <th class="ui-state-default" colspan="3"><h:outputText value="Order frequency : weekly"/></th>
                            </tr>

                            <tr>
                                <th class="ui-state-default" colspan="3"><h:outputText value="#{mrpMrpViewManagerBean.getMonthEnglish(mrpMrpViewManagerBean.selectedMRP.startPeriodMonth)}"/></th>
                                <th class="ui-state-default">Week 1</th>
                                <th class="ui-state-default">Week 2</th>
                                <th class="ui-state-default">Week 3</th>
                                <th class="ui-state-default">Week 4</th>
                                <th class="ui-state-default">Week 5</th>
                            </tr>

                            <tr>
                                <th class="ui-state-default" rowspan="5">MPS (cases)</th>
                            </tr>

                            <c:forEach items="#{mrpMrpViewManagerBean.counterForProduct}" var="product">
                                <tr>
                                    <th class="ui-state-default" colspan="2"><h:outputText value="#{mrpMrpViewManagerBean.returnProductName(product)}"/></th>
                                    <c:forEach items="#{mrpMrpViewManagerBean.counterForWeek}" var="day">
                                        <td><h:outputText value="#{mrpMrpViewManagerBean.weeklyDemands.get(product).get(day)}" 
                                                          rendered="#{mrpMrpViewManagerBean.renderCell(day)}"/>
                                            <h:outputText value="" rendered="#{!mrpMrpViewManagerBean.renderCell(day)}"/>
                                        </td>
                                    </c:forEach>
                                </tr>
                            </c:forEach>
                            
                            <tr>
                                <th class="ui-state-default" rowspan="5">MRP (kg)</th>
                            </tr>

                            <c:forEach items="#{mrpMrpViewManagerBean.counterForProduct}" var="product">
                                <tr>
                                    <th class="ui-state-default" colspan="2"><h:outputText value="#{mrpMrpViewManagerBean.returnProductName(product)}"/></th>
                                    <c:forEach items="#{mrpMrpViewManagerBean.counterForWeek}" var="day">
                                        <td><h:outputText value="#{mrpMrpViewManagerBean.returnKG(mrpMrpViewManagerBean.weeklyDemands.get(product).get(day), product)}"
                                                          rendered="#{mrpMrpViewManagerBean.renderCell(day)}">
                                                <f:convertNumber pattern="#.##"/>
                                            </h:outputText>
                                            <h:outputText value="" rendered="#{!mrpMrpViewManagerBean.renderCell(day)}"/>
                                        </td>
                                    </c:forEach>
                                </tr>
                            </c:forEach>

                            <tr>
                                <th class="ui-state-default" colspan="3">Gross Requirements (kg)</th>
                                <c:forEach items="#{mrpMrpViewManagerBean.counterForWeek}" var="day">
                                    <td><h:outputText value="#{mrpMrpViewManagerBean.returnGrossRequirements(day)}" 
                                                      rendered="#{mrpMrpViewManagerBean.renderCell(day)}"/>
                                        <h:outputText value="" rendered="#{!mrpMrpViewManagerBean.renderCell(day)}"/>
                                    </td>
                                </c:forEach>
                            </tr>

                            <tr>
                                <th class="ui-state-default" colspan="3">Planned Receipts (kg)</th>
                                <c:forEach items="#{mrpMrpViewManagerBean.selectedMRP.plannedReceipts}" var="item">
                                    <td><h:outputText value="#{item.longValue}"/>
                                    </td>
                                </c:forEach>
                                <td><h:outputText value="" rendered="#{mrpMrpViewManagerBean.renderEmpty()}"/></td>
                            </tr>

                            <tr>
                                <th class="ui-state-default" colspan="2">Planned Inventory</th>
                                <td><h:outputText value="#{mrpMrpViewManagerBean.returnPrevInventory()}"/></td>
                                <c:forEach items="#{mrpMrpViewManagerBean.selectedMRP.plannedInventory}" var="item">
                                    <td><h:outputText value="#{item.longValue}"/>
                                    </td>
                                </c:forEach>
                                <td><h:outputText value="" rendered="#{mrpMrpViewManagerBean.renderEmpty()}"/></td>
                            </tr>

                        </tbody>
                    </table>
                </div>
            </div>
        </h:form>
    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>
